package com.example.spark.controller;

import com.example.spark.entity.GroupIntro;
import com.example.spark.entity.result.CommonResult;
import com.example.spark.service.GroupIntroService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@CrossOrigin
@RequestMapping("/introduction")
@RestController
public class GroupIntroController {
    @Autowired
    private GroupIntroService gpService;

    /**
     * 添加小组介绍
     *
     * @param groupIntro 小组介绍
     * @return CommonResult
     */
    @PostMapping("/addIntro")
    public CommonResult add(@RequestBody GroupIntro groupIntro) {
        return gpService.add(groupIntro);
    }

    /**
     * 添加/修改小组介绍图片
     *
     * @param file 图片文件
     * @param id 小组介绍id
     * @return CommonResult
     * @throws IOException
     */
    @PutMapping("/updateIntroPicture/{id}")
    public CommonResult addPicture(@RequestParam MultipartFile file,@PathVariable Long id) throws IOException {
        return gpService.addPicture(file,id);
    }
    /**
     * 查询小组介绍
     *
     * @return CommonResult<IPage < GroupIntro>>
     */
    @GetMapping("/getIntro")
    public CommonResult getAll() {
        return  gpService.get();
    }

    /**
     * 删除小组介绍
     *
     * @param id 小组介绍id
     * @return ComonResult
     */
    @DeleteMapping("/deleteIntro/{id}")
    public CommonResult deleteById(@PathVariable Long id) {
        return gpService.deleteById(id);
    }

    /**
     * 更新小组介绍
     *
     * @param groupIntro 小组介绍
     * @return CommonResult
     */
    @PutMapping("/updateIntro")
    public CommonResult update(@RequestBody GroupIntro groupIntro) {
        return gpService.update(groupIntro);
    }

}
